#include<iostream>
#include"TcpServer.hpp"
#include<memory>
#include"Servercal.hpp"


Servercal cal;

void OnHandler(std::weak_ptr<Connection> con_ptr)
{
    if(con_ptr.expired()) return;
    auto it = con_ptr.lock();

    std::string& info = it->GetInbuffer();
    std::cout<< "server get a message: " << info;

    //todo,处理info
    std::string response = cal.Calculate(info);
    if(response.empty()) return;
    it->AppendOutbuffer(response);

    it->sendcb_(it);
}


int main()
{
    std::shared_ptr<Tcpserver> tsvr_ptr(new Tcpserver(8888,OnHandler));
    tsvr_ptr->Init();
    tsvr_ptr->loop();
    return 0;
}